package org.wishwork.api.token;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wishwork.JSTService;
import org.wishwork.api.token.get.GetToken;
import org.wishwork.api.token.refresh.RefreshToken;
import org.wishwork.constant.Constants;
import org.wishwork.context.Context;

import java.io.IOException;

/**
 * @description: token 相关操作
 * @author: WangYX
 * @create: 2022-04-01 16:59
 * @Version: 1.0.0
 **/

public class TokenApi {

    private static final Logger log = LoggerFactory.getLogger(JSTService.class);

    private Context context;

    private final GetToken getToken;

    private final RefreshToken refreshToken;

    public TokenApi(Context context) {
        this.context = context;
        this.getToken = new GetToken(context);
        this.refreshToken = new RefreshToken(context);
    }

    /**
     * 获取token
     *
     * @return
     */
    public String token(String code) throws IOException {
        return this.getToken.getToken(code);
    }

    /**
     * 利用RefreshToken重新刷新token
     *
     * @param refreshToken
     * @return
     * @throws IOException
     */
    public String refresh(String refreshToken) throws IOException {
        return this.refreshToken.refreshToken(refreshToken);
    }


}
